public void ShouldReturnMultipleVMRoleVMs() { var mockChannel = new MockRequestChannel(); var vmRole = new VMRole { Name = vmRoleName, Label = vmRoleLabel }; var vmList = new List <VM> { new VM() { Id = Guid.Empty }, new VM() { Id = Guid.Empty } }; vmRole.VMs.Load(vmList); mockChannel.AddReturnObject(vmRole); var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel)); var readVMRole = vmRoleOperations.Read(cloudServiceName, vmRoleName); Assert.Equal(vmRoleName, readVMRole.Name); Assert.Equal(vmList.Count, readVMRole.VMs.Count); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(2, requestList.Count); Assert.Equal(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1)); }
public static bool Insert(VMRole paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_role a = new m_role(); a.code = paramModel.code; a.name = paramModel.name; a.description = paramModel.description; a.is_delete = paramModel.is_delete; a.created_by = paramModel.created_by; a.created_date = paramModel.created_date; db.m_role.Add(a); db.SaveChanges(); } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
public static bool Delete(VMRole paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_role a = db.m_role.Where(o => o.id == paramModel.id).FirstOrDefault(); if (a != null) { a.is_delete = true; db.SaveChanges(); } else { result = false; } } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
public ActionResult Edit(int id, VMRole data) { try { if (ModelState.IsValid) { using (Context ctx = new Context()) { ctx.RoleUpdateJust(id, data); // since we just changed a role, should also update the // current users role string so they are able to use // the new role info instantly // other users will have to log out and log back in Borrower b = Authentication.GetCurrentUser(ctx); Session["AUTHRole"] = ctx.GetRoleString(b); return(RedirectToAction("Index")); } } return(View(data)); } catch (Exception ex) { return(View("Exception", ex)); } }
public async Task <IList <VMRole> > SearchAsync(VMRole entity) { _logger.LogInformation("Searching for role using 'Dapper', {@entity}", entity); using (var connection = _dbContext.Database.GetDbConnection()) { var paramObj = new { Code = entity.Code == null ? "" : entity.Code, Name = entity.Name == null ? "" : entity.Name, CreatedBy = entity.CreatedBy == null ? "" : entity.CreatedBy, CreatedDate = entity.CreatedDate == null ? "" : entity.CreatedDate }; var result = await connection.QueryAsync <VMRole>("SearchRole", param : paramObj, commandType : CommandType.StoredProcedure); if (result == null || result.Count() == 0) { throw new Exception("Data not found"); } var resultList = result.ToList(); return(resultList); } }
public ActionResult Edit(VMRole paramModel) { try { RoleRepo.Message = string.Empty; paramModel.updated_by = "Dzul"; paramModel.updated_date = DateTime.Now; if (null == paramModel.name) { RoleRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali"; } if (string.IsNullOrEmpty(RoleRepo.Message)) { return(Json(new { success = RoleRepo.Update(paramModel), message = RoleRepo.Message }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = RoleRepo.Message }, JsonRequestBehavior.AllowGet)); } } catch (Exception hasError) { return(Json(new { success = false, message = hasError.Message }, JsonRequestBehavior.AllowGet)); } }
// GET: Role/Create public ActionResult Create() { try { var data = new VMRole(); return(View(data)); } catch (Exception ex) { return(View("Exception", ex)); } }
public async Task <IActionResult> OnGetSearchAsync(VMRole roleView) { try { var roles = await _mRoleService.SearchAsync(roleView); return(Partial("MRolePartials/_ViewList", roles)); } catch (Exception ex) { _logger.LogError("Error occured, {@ex}", ex); return(BadRequest(ex.Message)); } }
public ActionResult Create(VMRole paramModel) { try { RoleRepo.Message = string.Empty; //Create auto generate product_code using (var db = new Markom_IDLEEntities()) { string nol = ""; m_role cek = db.m_role.OrderByDescending(x => x.code).First(); int simpan = int.Parse(cek.code.Substring(3)); simpan++; for (int i = simpan.ToString().Length; i < 4; i++) { nol = nol + "0"; } paramModel.code = "MN" + nol + simpan; } paramModel.created_by = "Administrator"; paramModel.created_date = DateTime.Now; paramModel.is_delete = false; if (null == paramModel.name) { RoleRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali"; } if (string.IsNullOrEmpty(RoleRepo.Message)) { return(Json(new { success = RoleRepo.Insert(paramModel), message = paramModel.code }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = RoleRepo.Message }, JsonRequestBehavior.AllowGet)); } } catch (Exception hasError) { return(Json(new { success = false, message = hasError.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(VMRole paramModel) { try { return(Json(new { success = RoleRepo.Delete(paramModel), message = RoleRepo.Message }, JsonRequestBehavior.AllowGet)); } catch (Exception hasError) { return(Json(new { success = false, message = hasError.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id, VMRole data) { try { if (ModelState.IsValid) { using (Context ctx = new Context()) { ctx.RoleDelete(id); return(RedirectToAction("Index")); } } return(View(data)); } catch (Exception ex) { return(View("Exception", ex)); } }
public static VMRole GetDetailById(int Id) { VMRole result = new VMRole(); using (var db = new Markom_IDLEEntities()) { result = (from a in db.m_role where a.id == Id select new VMRole { id = a.id, code = a.code, name = a.name, description = a.description, is_delete = a.is_delete, created_by = a.created_by, created_date = a.created_date, updated_by = a.updated_by, updated_date = a.updated_date }).FirstOrDefault(); } return(result); }
public void ShouldCreateOneVMRole() { var mockChannel = new MockRequestChannel(); var vmRoleToCreate = new VMRole { Name = vmRoleName, Label = vmRoleLabel }; var vmRoleToReturn = new VMRole { Name = vmRoleName, Label = vmRoleLabel, }; mockChannel.AddReturnObject(vmRoleToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid?jobOut; var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdVMRole = vmRoleOperations.Create(cloudServiceName, vmRoleToCreate, out jobOut); Assert.IsNotNull(createdVMRole); Assert.IsInstanceOfType(createdVMRole, typeof(VMRole)); Assert.AreEqual(vmRoleToReturn.Name, createdVMRole.Name); Assert.AreEqual(vmRoleToReturn.Label, createdVMRole.Label); var requestList = mockChannel.ClientRequests; Assert.AreEqual(1, requestList.Count); Assert.AreEqual(HttpMethod.Post.ToString(), requestList[0].Item1.Method); // Check the URI (for Azure consistency) Assert.AreEqual(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public override void ExecuteCmdlet() { Guid? vmRolejobId = Guid.Empty; VMRole createdVmRole = null; IEnumerable <VMRole> results = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); var newVMRole = new VMRole() { Name = this.Name, Label = this.Label, ResourceDefinition = this.ResourceDefinition, InstanceView = null, ResourceConfiguration = null, ProvisioningState = null, Substate = null, }; if (this.ParameterSetName == WAPackCmdletParameterSets.QuickCreate) { var cloudService = new Utilities.WAPackIaaS.DataContract.CloudService() { Name = this.Name, Label = this.Label }; Guid?cloudServiceJobId = Guid.Empty; var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); cloudServiceOperations.Create(cloudService, out cloudServiceJobId); WaitForJobCompletion(cloudServiceJobId); try { createdVmRole = vmRoleOperations.Create(this.Name, newVMRole, out vmRolejobId); WaitForJobCompletion(vmRolejobId); var vmRole = vmRoleOperations.Read(this.Name, this.Name); results = new List <VMRole>() { vmRole }; } catch (Exception) { cloudServiceOperations.Delete(this.Name, out cloudServiceJobId); WaitForJobCompletion(cloudServiceJobId); throw; } } else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService) { createdVmRole = vmRoleOperations.Create(this.CloudService.Name, newVMRole, out vmRolejobId); WaitForJobCompletion(vmRolejobId); var vmRole = vmRoleOperations.Read(this.CloudService.Name, this.Name); results = new List <VMRole>() { vmRole }; } this.GenerateCmdletOutput(results); }
public static VMRole CreateVMRole(string name) { VMRole vMRole = new VMRole(); vMRole.Name = name; return vMRole; }