コード例 #1
0
ファイル: DerService.cs プロジェクト: cobianwae/Pear
        public CreateOrUpdateResponse CreateOrUpdate(CreateOrUpdateDerRequest request)
        {
            var response = new CreateOrUpdateResponse();
            try
            {
                if (request.Id > 0)
                {
                    var der = DataContext.Ders.Single(x => x.Id == request.Id);
                    der.IsActive = request.IsActive;
                    der.Title = request.Title;
                    DataContext.Entry(der).State = EntityState.Modified;
                }
                else
                {
                    var der = new Der();
                    der.IsActive = request.IsActive;
                    der.Title = request.Title;
                    DataContext.Ders.Add(der);
                }

                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "DER has been added successfully";
            }
            catch (Exception exception)
            {
                response.IsSuccess = false;
                response.Message = exception.Message;
            }

            return response;
        }
コード例 #2
0
ファイル: DerService.cs プロジェクト: fazar/Pear
        public CreateOrUpdateResponse CreateOrUpdate(CreateOrUpdateDerRequest request)
        {
            var response = new CreateOrUpdateResponse();
            try
            {
                var existingDer = DataContext.Ders.FirstOrDefault(s => s.Title == request.Title);
                var user = new User { Id = request.RevisionBy };
                DataContext.Users.Attach(user);
                if (existingDer != null)
                {
                    existingDer.IsActive = request.IsActive;
                    existingDer.Title = request.Title;
                    existingDer.Date = request.Date;
                    existingDer.Filename += ";" + request.Filename;
                    existingDer.RevisionBy = user;
                    existingDer.Revision = existingDer.Revision + 1;
                }
                else
                {
                    var der = new Der();
                    der.IsActive = request.IsActive;
                    der.Title = request.Title;
                    der.Date = request.Date;
                    der.Filename = request.Filename;
                    der.RevisionBy = user;
                    der.GenerateBy = user;
                    der.Revision = 0;
                    DataContext.Ders.Add(der);
                }

                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "DER has been added successfully";
            }
            catch (Exception exception)
            {
                response.IsSuccess = false;
                response.Message = exception.Message;
            }

            return response;
        }