Beispiel #1
0
        public async Task <double> UpdateProfileAmountAsync(int employeeId, int profileId, double amount)
        {
            try
            {
                var context = new ElementContext();
                var profile = context.Profiles.Find(profileId);
                if (profile != null)
                {
                    if (profile.Count > amount && amount > 0)
                    {
                        profile.Amount = amount;
                        profile.ElementInfos.Add(new ElementInfo()
                        {
                            Amount = amount, EmployeeId = employeeId, Time = DateTime.Now
                        });

                        context.Entry(profile).State = EntityState.Modified;
                        var result = await context.SaveChangesAsync();

                        if (result > 0)
                        {
                            return(await Task.FromResult(profile.Amount));
                        }
                    }
                }

                return(await Task.FromResult <double>(-1));
            }
            catch (Exception ex)
            {
                PrintException(ex);
                throw new FaultException(ex.Message, new FaultCode("UpdateProfileAmountAsync"), "UpdateProfileAmountAsync");
            }
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "IdElement,IdCategory,Content")] Element element)
 {
     if (ModelState.IsValid)
     {
         db.Entry(element).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Main", "Home"));
     }
     return(View(element));
 }
Beispiel #3
0
 public async Task <bool> DeleteProfileAsync(int profileId)
 {
     try
     {
         using (var context = new ElementContext())
         {
             var profile = context.Profiles.SingleOrDefault(x => x.ProfileId == profileId);
             Console.WriteLine($"Name: {profile.ProfileNumber}");
             context.Entry(profile).State = EntityState.Deleted;
             return(await context.SaveChangesAsync() > 0);
         }
     }
     catch (Exception ex)
     {
         PrintException(ex);
         throw new FaultException(ex.Message, new FaultCode("DeleteProfileAsync"), "DeleteProfileAsync");
     }
 }
Beispiel #4
0
        /*
         *      var context = new EmployeeContext();
         *      var entity = AutoMapperConfiguration.Mapper.Map<Division>(division);
         *      var result = context.Divisions.Find(division.DivisionId);
         *      if (result != null)
         *      {
         *          result.Description = entity.Description;
         *          result.DivisionInfoId = entity.DivisionInfoId;
         *          result.DivisionType = entity.DivisionType;
         *          result.Name = entity.Name;
         *          context.Entry(result).State = EntityState.Modified;
         *          context.Entry(result.DivisionType).State = EntityState.Modified;
         *          return await context.SaveChangesAsync();
         *      }
         *      else
         *      {
         *          context.Divisions.Attach(entity);
         *          context.Divisions.Add(entity);
         *
         *          var divisionId = await context.SaveChangesAsync();
         *          if (divisionId > 0)
         *          {
         *              return await Task.FromResult(entity.DivisionId);
         *          }
         *          else
         *          {
         *              return await Task.FromResult(0);
         *          }
         *      }
         */

        public async Task <bool> UpdateProfileAsync(int employeeId, ProfileDTO profile)
        {
            try
            {
                var context = new ElementContext();
                var entity  = AutoMapperConfiguration.Mapper.Map <Profile>(profile);
                var result  = context.Profiles.Find(profile.ProfileId);
                if (result != null)
                {
                    if (result.Amount != entity.Amount)
                    {
                        result.ElementInfos.Add(new ElementInfo {
                            Amount = entity.Amount, Time = DateTime.Now, EmployeeId = employeeId
                        });
                    }

                    result.Amount               = entity.Amount;
                    result.Contraction          = entity.Contraction;
                    result.Count                = entity.Count;
                    result.Description          = entity.Description;
                    result.Length               = entity.Length;
                    result.ProfileNumber        = entity.ProfileNumber;
                    result.Surface              = entity.Surface;
                    context.Entry(result).State = EntityState.Modified;
                    if (await context.SaveChangesAsync() > 0)
                    {
                        return(await Task.FromResult(true));
                    }
                }

                return(await Task.FromResult(false));
            }
            catch (Exception ex)
            {
                PrintException(ex);
                throw new FaultException(ex.Message, new FaultCode("UpdateProfileAsync"), "UpdateProfileAsync");
            }
        }