public List <AssetLocationViewModel> Pagination_AssetLocation_SP(int Skip) { var result = new List <AssetLocationViewModel>(); var obj = new AssetLocationViewModel(); using (AstonContext dbContext = new AstonContext()) { dbContext.Database.OpenConnection(); DbCommand cmd = dbContext.Database.GetDbConnection().CreateCommand(); cmd.CommandText = "dbo.sp_AssetLocation_Pagination"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Skip", SqlDbType.Int) { Value = Skip }); using (var reader = cmd.ExecuteReader()) { var assetlocationlist = dbContext.DataReaderMapToList <AssetLocationPagination>(reader); foreach (var assetlocation in assetlocationlist) { result.Add(new AssetLocationViewModel() { AssetLocation = assetlocation }); } cmd.Connection.Close(); } } return(result); }
public HttpResponseMessage CreateAssetLocation(HttpRequestMessage request, [FromBody] AssetLocationViewModel obj) { var result = service.CreateAssetLocation(obj); HttpResponseMessage response = new HttpResponseMessage(); response = request.CreateResponse(HttpStatusCode.OK, new { success = result.status }); return(response); }
public HttpResponseMessage CreateAssetLocation(AssetLocationViewModel obj) { HttpResponseMessage result = default(HttpResponseMessage); string requestUri = "api/AssetLocation/CreateAssetLocation"; result = REST(requestUri, RESTConstants.POST, JsonConvert.SerializeObject(obj)); return(result); }
public HttpResponseMessage CreateAssetLocation(HttpRequestMessage request, [FromBody] AssetLocationViewModel obj) { HttpResponseMessage response = new HttpResponseMessage(); obj.CreatedBy = User.Identity.Name; response = _assetLocationProcess.CreateAssetLocation(obj); return(response); }
/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(AssetLocationViewModel model) { var entity = model.ToEntity(); this._AssetLocationsRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
public ActionResult New() { var assetLocationVm = new AssetLocationViewModel() { Organizations = _organizationManager.GetAll(), Branches = new List <Branch>() { } }; return(View("LocationForm", assetLocationVm)); }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">AssetLocation view model</param> public void ThrowExceptionIfExist(AssetLocationViewModel model) { //ConditionFilter<AssetLocation, long> condition = new ConditionFilter<AssetLocation, long> //{ // Query = (entity => // entity.Code == model.Code && // entity.Id != model.Id) //}; //var existEntity = this._AssetLocationsRepository.Get(condition).FirstOrDefault(); //if (existEntity != null) // throw new ItemAlreadyExistException((int)ErrorCodeEnum.CodeAlreadyExist); }
public ActionResult Save(AssetLocationViewModel assetLocationVm) { var assetLocationVmDropdown = new AssetLocationViewModel() { Organizations = _organizationManager.GetAll(), Branches = new List <Branch>() { } }; ModelState.Remove("Id"); if (ModelState.IsValid) { if (assetLocationVm.Id == 0) { bool isShortNameExist = _assetLocationManager.IsShortNameExist(assetLocationVm.ShortName, assetLocationVm.OrganizationId, assetLocationVm.BranchId); if (isShortNameExist) { ViewBag.Message = "This Location Short Name already Exist"; return(View("LocationForm", assetLocationVmDropdown)); } var location = new AssetLocation() { OrganizationId = assetLocationVm.OrganizationId, BranchId = assetLocationVm.BranchId, Name = assetLocationVm.Name, ShortName = assetLocationVm.ShortName, BranchCode = assetLocationVm.LocationCode }; _assetLocationManager.Add(location); ModelState.Clear(); return(View("LocationForm", assetLocationVmDropdown)); } var locationInDb = _assetLocationManager.Get(assetLocationVm.Id); locationInDb.Id = assetLocationVm.Id; locationInDb.Name = assetLocationVm.Name; locationInDb.ShortName = assetLocationVm.ShortName; locationInDb.BranchCode = assetLocationVm.LocationCode; locationInDb.OrganizationId = assetLocationVm.OrganizationId; locationInDb.BranchId = assetLocationVm.BranchId; _assetLocationManager.Update(locationInDb); ModelState.Clear(); return(View("LocationList")); } return(View("LocationForm", assetLocationVmDropdown)); }
public List <AssetLocationViewModel> Pagination_AssetLocation_SP(int Skip) { var result = new List <AssetLocationViewModel>(); var obj = new AssetLocationViewModel(); using (NpgsqlConnection connection = new NpgsqlConnection(ConfigureSetting.GetConnectionString)) { connection.Open(); string sql = "sp_assetlocation_pagination"; using (NpgsqlCommand command = new NpgsqlCommand(sql, connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@skip", NpgsqlTypes.NpgsqlDbType.Integer, Skip); using (var reader = command.ExecuteReader()) { //make single level list while (reader.Read()) { result.Add(new AssetLocationViewModel() { AssetLocation = new AssetLocationPagination { ID = Convert.ToInt32(reader[0]), AssetID = Convert.ToInt32(reader[1]), LocationID = Convert.ToInt32(reader[2]), OnTransition = Convert.ToBoolean(reader[3]), MovementRequestDetailID = Convert.ToInt32(reader[4]), LocationName = reader[5].ToString(), AssetName = reader[6].ToString(), TotalRow = Convert.ToInt32(reader[7]) } }); } } } connection.Close(); } return(result); }
public AssetLocationViewModel GetAssetLocationByID(int id) { AssetLocationViewModel result = new AssetLocationViewModel(); var assetlocation = _assetlocation.GetAssetLocationByID(id); if (assetlocation != null) { result.AssetLocation.ID = assetlocation.ID; result.AssetLocation.AssetID = assetlocation.AssetID; result.AssetLocation.AssetName = assetlocation.Asset.Name; result.AssetLocation.LocationID = assetlocation.LocationID; result.AssetLocation.LocationName = assetlocation.Location.Name; result.AssetLocation.OnTransition = assetlocation.OnTransition; result.AssetLocation.MovementRequestDetailID = assetlocation.MovementRequestDetailID; } return(result); }
public List <AssetLocationViewModel> GetAssetLocationByLocationID(int id) { List <AssetLocationViewModel> result = new List <AssetLocationViewModel>(); var assetlocation = _assetlocation.GetAssetLocationByLocationID(id); if (assetlocation != null) { foreach (var item in assetlocation) { AssetLocationViewModel model = new AssetLocationViewModel(); model.ID = item.ID; model.AssetID = item.AssetID; model.AssetName = item.Asset.Name; model.LocationID = item.LocationID; model.LocationName = item.Location.Name; model.OnTransition = item.OnTransition; model.MovementRequestDetailID = item.MovementRequestDetailID; result.Add(model); } } return(result); }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public AssetLocationViewModel Update(AssetLocationViewModel model) { this.ThrowExceptionIfExist(model); // var entity = model.ToEntity(); var entity = this._AssetLocationsRepository.Get(model.Id); if (entity.AssetId != model.AssetId) { entity = this._AssetLocationsRepository .Get(null) .OrderByDescending(x => x.Id) .Where(x => x.AssetId == model.AssetId) .FirstOrDefault(); } if (entity.LocationId != model.LocationId) { entity = new AssetLocation { LocationId = model.LocationId, AssetId = model.AssetId, Date = DateTime.Now }; entity = this._AssetLocationsRepository.Add(entity); var entityAr = new AssetLocation { Id = entity.Id, Description = model.DescriptionAr, Language = Language.Arabic }; entity.ChildTranslatedAssetLocations.Add(entityAr); this._AssetLocationsRepository.Add(entityAr); var entityEn = new AssetLocation { Id = entity.Id, Description = model.DescriptionEn, Language = Language.English }; entity.ChildTranslatedAssetLocations.Add(entityEn); this._AssetLocationsRepository.Add(entityEn); } else { entity = this._AssetLocationsRepository.Update(entity); ConditionFilter <AssetLocation, long> conditionFilter = new ConditionFilter <AssetLocation, long>() { Query = (x => x.ParentKeyAssetLocationId == entity.Id) }; var childs = this._AssetLocationsRepository.Get(conditionFilter); if (childs.Count() > 0) { var ar = childs.FirstOrDefault(x => x.Language == Language.Arabic); ar.Description = model.DescriptionAr; this._AssetLocationsRepository.Update(ar); var en = childs.FirstOrDefault(x => x.Language == Language.English); en.Description = model.DescriptionEn; this._AssetLocationsRepository.Update(en); } } #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public ResultViewModel CreateAssetLocation(AssetLocationViewModel obj) { ResultViewModel result = new ResultViewModel(); IDbContextTransaction transaction = _context.Database.BeginTransaction(); if (obj != null) { try { var movementrequestdetail = _context.MovementRequestDetail.Where(p => p.ID == obj.AssetLocation.MovementRequestDetailID).FirstOrDefault(); var movementrequest = _context.MovementRequest.Where(p => p.ID == movementrequestdetail.MovementRequestID).FirstOrDefault(); var checkassetlocation = _context.AssetLocation.Where(p => p.MovementRequestDetailID == obj.AssetLocation.MovementRequestDetailID && p.DeletedDate == null).Count(); int totalmoved = 0; totalmoved = (movementrequestdetail.Quantity - checkassetlocation); if (obj.AssetLocationList.Count() <= totalmoved) { foreach (var item in obj.AssetLocationList) { AssetLocation assetlocationobj = new AssetLocation(); assetlocationobj.AssetID = item.AssetID; assetlocationobj.LocationID = movementrequest.LocationID; assetlocationobj.OnTransition = obj.AssetLocation.OnTransition; assetlocationobj.CreatedDate = obj.CreatedDate;//DateTime.Now; assetlocationobj.CreatedBy = obj.CreatedBy; assetlocationobj.MovementRequestDetailID = obj.AssetLocation.MovementRequestDetailID; _context.AssetLocation.Add(assetlocationobj); } _context.SaveChanges(); transaction.Commit(); result.status = true; } else { result.message = "the inputed asset exceed the requested asset"; result.status = false; } } catch (Exception ex) { transaction.Rollback(); result.message = ex.Message; result.status = false; } } else { result.status = false; result.message = "The object is null"; } return(result); }