Beispiel #1
0
        public async Task <IHttpActionResult> Update(long id, [FromBody] Machinery entity)
        {
            var resp = new ResponseData <Machinery>();

            try
            {
                var query = from a in DataContext.Machinery
                            where a.Id == id
                            select a;
                var error = "";
                var data  = query.FirstOrDefault();
                if (data == null)
                {
                    error        = $"data {id} not found";
                    resp.Message = error;
                }
                else
                {
                    Utils.CopyProperties(entity, data, ID_EXCEPTION);
                    DataContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
                    await DataContext.SaveChangesAsync();

                    resp.Data = data;
                }
            }
            catch (Exception ex)
            {
                resp.Message = ex.Message;
                Logger.LogError("Update Gesture error", ex);
            }
            return(Json(resp));
        }
Beispiel #2
0
        public async Task <ActionResult <Machinery> > Post([FromForm] MachineryDto model)
        {
            var user = await _accountRepository.GetByIdAsync(model.User);

            string path     = Path.Combine("img/customers", model.CustomerId.ToString(), "machinery");
            string pathFull = _baseUrl.GetBaseUrl(path);
            var    data     = new Machinery
            {
                Brand                   = model.Brand,
                CategoryId              = model.CategoryId,
                CustomerId              = model.CustomerId,
                DateOfPurchase          = model.DateOfPurchase,
                Model                   = model.Modelo,
                NameMachinery           = model.NameMachinery,
                Observations            = model.Observations,
                Serie                   = model.Serie,
                State                   = model.State,
                TechnicalSpecifications = model.TechnicalSpecifications,
                Ubication               = model.Ubication,
                User = user,
            };

            if (model.Img != null)
            {
                string nameFile = _imgService.SaveFile(model.Img, pathFull, 1280, 720);
                if (model.PhotoPath != null)
                {
                    await _imgService.DeleteFile(pathFull, model.PhotoPath);
                }
                data.PhotoPath = nameFile;
            }
            await _genericRepository.CreateAsync(data);

            return(new CreatedAtRouteResult("GetMachinery", new { id = data.Id }, data));
        }
Beispiel #3
0
        public Machinery Save([FromBody] Machinery entity)
        {
            ModelState.Validate();

            try
            {
                if (entity.Id > 0)
                {
                    _repository.Update(entity);
                }
                else
                {
                    _repository.Insert(entity);
                }
            }
            catch (SqlException e)
            {
                if (e.Number == 2627)
                {
                    throw new PawnshopApplicationException("Поле номер техпаспорта должно быть уникальным");
                }
                throw new PawnshopApplicationException(e.Message);
            }
            catch (Exception e)
            {
                throw new PawnshopApplicationException(e.Message);
            }

            return(entity);
        }
Beispiel #4
0
        public async Task <IHttpActionResult> Add([FromBody] Machinery entity)
        {
            DataContext.Machinery.Add(entity);
            await DataContext.SaveChangesAsync();

            return(Json(new ResponseData <Machinery>()
            {
                Data = entity
            }));
        }
Beispiel #5
0
 public void CopyFrom(Machinery machine)
 {
     Id   = machine.Id;
     Name = machine.Name;
     if (machine.Type != null)
     {
         TypeId   = machine.Type.Id;
         TypeName = machine.Type.Name;
     }
 }
Beispiel #6
0
        public int CreateMachinery(Record record)
        {
            Machinery machinery = new Machinery();

            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                machinery.title       = record.Name;
                machinery.Description = record.Description;
                machinery.Status      = (int)Record.StatusType.PREMODERATION;
                machinery.Category    = record.CategoryID;
                machinery.UserAuthor  = record.UserAuthorID;
                context.Machineries.InsertOnSubmit(machinery);
                context.Machineries.Context.SubmitChanges();

                foreach (Specification sp in record.Specifications)
                {
                    if (!CreateSpecifications(sp, machinery.Id))
                    {
                        throw new Exception("Невожно создать спецификацию");
                    }
                }
                if (record.Tags != null)
                {
                    foreach (Tag tag in record.Tags)
                    {
                        CreateTag(tag, machinery.Id);
                    }
                }
            }
            catch
            {
                return(0);
            }
            return(machinery.Id);
        }
Beispiel #7
0
 private void ChangeType(Machinery machine, int newTypeId, out IList <Work> conflictWorks)
 {
     conflictWorks = null;
     if (machine.Type.Id != newTypeId)
     {
         var newType = dbManager.GetById <MachineryType>(newTypeId);
         if (CompareAreas(machine, newType))
         {
             machine.SetType(newType);
         }
         else
         {
             IList <Work> works = FindConflicts(machine);
             if (works.Count == 0)
             {
                 machine.SetType(newType);
             }
             else
             {
                 conflictWorks = works;
             }
         }
     }
 }
 public void Update(Machinery entity)
 {
     DatabaseFactory.CreateDatabase()
     .ExecuteNonQuery("UPDATE_MACHINERY_SP", entity.Id, entity.Brand, entity.Model, entity.SerialNumber,
                      entity.LifeHours, entity.CreatedBy, entity.CreationDate);
 }
 public IList <Machinery> GetPaginated(Machinery filters, int pageIndex, int pageSize, out int totalRows)
 {
     throw new System.NotImplementedException();
 }
Beispiel #10
0
 private bool CompareAreas(Machinery machine, MachineryType anyType)
 => anyType.Areas.Any(x => machine.Type.Areas.Any(z => x.Id == z.Id));
Beispiel #11
0
 private IList <Work> FindConflicts(Machinery machine)
 => dbManager.GetAll <Work>().Where(x => x.Parent.MachineryId == machine.Id).ToList();
        public ActionResult CreateUpdateMachinery(MachineryModel machineryModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            if (!CheckEmployeeHasBalance(machineryModel.Price))
            {
                return(ShowErrorMessage(Constant.InsufficientBalance));
            }

            var machinery = new Machinery();

            if (machineryModel.Id > 0)
            {
                machinery = FarmManagementEntities.Machineries.Single(x => x.Id == machineryModel.Id);
            }

            machinery.FarmId    = machineryModel.FarmId;
            machinery.VendorId  = machineryModel.VendorId;
            machinery.AccountId = machineryModel.AccountId;

            machinery.Name             = machineryModel.Name;
            machinery.Color            = machineryModel.Color;
            machinery.Type             = machineryModel.Type;
            machinery.RegistrationNo   = machineryModel.RegistrationNo;
            machinery.ModelNo          = machineryModel.ModelNo;
            machinery.CompanyName      = machineryModel.CompanyName;
            machinery.PurchaseDate     = machineryModel.PurchaseDate;
            machinery.OtherDescription = machineryModel.OtherDescription;

            machinery.Condition = machineryModel.MachineCondition.ToNullIfEmptyEnum <Condition>();

            var fileUploadLicense = ClientSession.FileUploads.Single(x => x.FileUploadGuid == machineryModel.MachineryGuid &&
                                                                     x.FileUploadName == FileUploadPath.MachineLicenseFile &&
                                                                     !x.HasRemoved);

            machinery.LicenseFile = System.IO.Path.GetFileName(fileUploadLicense.FilePath);

            var fileUploadPicture = ClientSession.FileUploads.Single(x => x.FileUploadGuid == machineryModel.MachineryGuid &&
                                                                     x.FileUploadName == FileUploadPath.MachinePicture &&
                                                                     !x.HasRemoved);

            machinery.Picture = System.IO.Path.GetFileName(fileUploadPicture.FilePath);

            if (machineryModel.Id == 0)
            {
                machinery.Price      = machineryModel.Price;
                machinery.InsertDate = DateTime.Now;
                machinery.UserId     = machineryModel.UserId;
                FarmManagementEntities.Machineries.Add(machinery);

                ManageEmployeeBalance(machineryModel.Price);
            }
            else
            {
                machinery.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            UpdateFileUploadPath(FileUploadPath.MachineLicenseFile, fileUploadLicense, machinery.Id);
            UpdateFileUploadPath(FileUploadPath.MachinePicture, fileUploadPicture, machinery.Id);
            ClearAllFileUpload();

            var message = string.Format(Constant.SuccessMessage, machineryModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }