コード例 #1
0
 public async Task Insert(AuditTrial model)
 {
     try
     {
         await _context.AuditTrials.InsertOneAsync(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        private AuditTrial BuildAuditTrialObject(string subscriptionNo, string message)
        {
            try
            {
                var user = _session.GetObjectFromJson <User>("User");

                var modal = new AuditTrial
                {
                    Date               = DateTime.UtcNow,
                    Description        = message,
                    SubscriptionNo     = subscriptionNo,
                    UserNameWhoUpdated = user.UserName
                };

                return(modal);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        /// <summary>
        /// Addes entry to the Audit trial
        /// </summary>
        /// <param name="account"></param>
        /// <param name="Status"></param>
        /// <param name="operationType"></param>
        /// <param name="RequestContext"></param>
        public static void AuditTrialEntry(User account, AuditTrialStatus Status, AuditTrialOpType operationType, HttpRequestMessage requestMessage, string roleId = null, string tokenId = null)
        {
            var        context         = requestMessage.Properties["MS_OwinContext"] as Microsoft.Owin.OwinContext;
            AuditTrial operationLogObj = new AuditTrial()
            {
                Id      = (Guid.NewGuid()).ToString(),
                UserId  = account.Id,
                RoleId  = roleId,
                TokenId = tokenId,
                //DeviceId = HttpUtilities.GetDeviceIDFromHeader(Request, account.Email),
                TypeofOperation    = operationType.ToString(),
                Status             = Status.ToString(),
                OperationTimeStamp = DateTimeOffset.UtcNow,
                CreatedBy          = account.Email,
                //ModifiedBy = account.Id,
                Deleted   = false,
                IPAddress = context.Request.RemoteIpAddress
            };

            dbContext.AuditTrials.Add(operationLogObj);
            dbContext.SaveChanges();
            //Enable this when account locking mechanism required.
            //var operationsobj = dbContext.AuditTrials.Where(item => item.UserId == account.Id && item.TypeofOperation == Constants.LOGIN_OPERATION
            //                                                && item.OperationTimeStamp >= account.UpdatedAt && account.ModifiedBy == account.Email
            //                                                && item.IsOffline == false)
            //                                    .OrderByDescending(item => item.OperationTimeStamp)
            //                                    .Take(3);

            //if (operationsobj.Count() > 0)
            //{
            //    if (operationsobj.Where(item => item.Status == Constants.FAILURE).Count() == 5)
            //    {
            //        account.IsLocked = true;
            //        _context.Entry(account).State = System.Data.Entity.EntityState.Modified;
            //        _context.SaveChanges();

            //    }
            //}
        }
コード例 #4
0
ファイル: Task.cs プロジェクト: nakash2050/DesignPatterns
 public Task()
 {
     _auditTrial = new AuditTrial();
 }
コード例 #5
0
        public async Task <IActionResult> Edit(SellDto sellDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    // Get All Model Errors and Join Them in One Sting Seperated by coma ","
                    var aLLmsg = Global.ModelErrorsToJoinString(ModelState, ",");
                    throw new ApplicationException(aLLmsg);
                }

                int UserBranchId = Convert.ToInt32(User.FindFirst(ClaimName.BranchId).Value);

                // Get Sell&Sell_Details Obj From DB where  1- sell not deleted  2- sell belongs to user Branch
                Sell sellToUpdate = await db.Sells.Include(s => s.Sell_Details).FirstOrDefaultAsync(s => s.sellId == sellDto.sellId && s.isDeleted != true && s.Location.BranchId == UserBranchId);

                if (sellToUpdate == null)
                {
                    return(NotFound());
                }


                await ResetLocationQtyAsync(sellToUpdate);

                // Delete Sell_Details
                db.Sell_Details.RemoveRange(sellToUpdate.Sell_Details);
                // Clear old Sell_Details from object to add New Sell_Details
                sellToUpdate.Sell_Details = null;

                // Mapping Sell Object and Sell_Details Object and Apply business requirements
                // Note maybe throw ApplicationException: in case un valid data for example : requsted quntity not available
                await PrepareSellObjectAsync(sellToUpdate, sellDto);

                //--------------------------------------------------------------------------------------------------------------------------------------------
                // Upload Sell Document {Note: the file was Validated by DataAnnotation in DTO model} (Note: Uploade Operation must come after all Validation)
                //--------------------------------------------------------------------------------------------------------------------------------------------
                if (sellDto.docment != null && sellDto.docment.Length != 0)
                {
                    // path for Old Document for This Sell Invoice
                    string deletedPath = Path.Combine(hostingEnvironment.WebRootPath, sellToUpdate.docment);
                    // Uploade New Document
                    sellToUpdate.docment = await FileManager.UploadFileAsync(sellDto.docment, hostingEnvironment.WebRootPath, FileSettings.SellDirectory);

                    //Delete Old Document
                    FileManager.RemoveFileFromServer(deletedPath);
                }
                //--------------------------------------------------------------------------------------------------------------------------------------------

                //--------------------------------------------------------------------------------------------------------------------------------------------
                // AuditTrial => Log Update Operation To DataBase
                //--------------------------------------------------------------------------------------------------------------------------------------------
                AuditTrial aditTrail = new AuditTrial()
                {
                    actionDate = DateTime.UtcNow,
                    ActionId   = Models.Action.Update,
                    // This will Throw Exception in case a ControllerName not Match one of Pages Enum Member
                    PageId   = Convert.ToInt32(Enum.Parse(typeof(Page.Pages), ControllerContext.ActionDescriptor.ControllerName.ToLower())),
                    recordId = sellToUpdate.sellId,
                    UserId   = Convert.ToInt64(User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value)
                };
                await db.AuditTrials.AddAsync(aditTrail);

                //--------------------------------------------------------------------------------------------------------------------------------------------

                await db.SaveChangesAsync();

                return(Json(new { isError = 0, msg = localizer["SavedSuccessfully"] }));
            }
            catch (ApplicationException ex)
            {
                return(Json(new
                {
                    isError = 1,
                    msg = ex.Message
                }));
            }
            catch (DbUpdateException ex)
            {
                Global.LogException(HttpContext, ex);

                return(Json(new
                {
                    isError = 1,
                    msg = localizer["UnableToSaveTryAgainOrCallUs"]
                }));
            }
            // Create New Sell_Details
            // Use New Sell_Details to Update Location_Qty {Decrease Operation}
            // Update Sell Obj Values
            // Insert Aduit Trails {Update Action}
        }
コード例 #6
0
        public async Task <IActionResult> Add(SellDto sellDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    // Get All Model Errors and Join Them in One Sting Seperated by coma ","
                    var aLLmsg = Global.ModelErrorsToJoinString(ModelState, ",");
                    throw new ApplicationException(aLLmsg);
                }

                Sell sell = new Sell();
                // Mapping Sell Object and Sell_Details Object and Apply business requirements
                // Note maybe throw ApplicationException: in case un valid data for example : requsted quntity not available
                await PrepareSellObjectAsync(sell, sellDto);

                //--------------------------------------------------------------------------------------------------------------------------------------------
                // Upload Sell Document {Note: the file was Validated by DataAnnotation in DTO model} (Note: Uploade Operation must come after all Validation)
                //--------------------------------------------------------------------------------------------------------------------------------------------
                if (sellDto.docment != null && sellDto.docment.Length != 0)
                {
                    sell.docment = await FileManager.UploadFileAsync(sellDto.docment, hostingEnvironment.WebRootPath, FileSettings.SellDirectory);
                }
                //--------------------------------------------------------------------------------------------------------------------------------------------

                using (var transaction = db.Database.BeginTransaction())
                {
                    //--------------------------------------------------------------------------------------------------------------------------------------------
                    // Insert Sell Object To DataBase
                    //--------------------------------------------------------------------------------------------------------------------------------------------
                    db.Sells.Add(sell);
                    await db.SaveChangesAsync();

                    //--------------------------------------------------------------------------------------------------------------------------------------------
                    // AuditTrial => Log Insert Operation To DataBase
                    //--------------------------------------------------------------------------------------------------------------------------------------------
                    AuditTrial aditTrail = new AuditTrial()
                    {
                        actionDate = DateTime.UtcNow,
                        ActionId   = Models.Action.Create,
                        // This will Throw Exception in case a ControllerName not Match one of Pages Enum Member
                        PageId   = Convert.ToInt32(Enum.Parse(typeof(Page.Pages), ControllerContext.ActionDescriptor.ControllerName.ToLower())),
                        recordId = sell.sellId,
                        UserId   = Convert.ToInt64(User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value)
                    };
                    await db.AuditTrials.AddAsync(aditTrail);

                    await db.SaveChangesAsync();

                    //--------------------------------------------------------------------------------------------------------------------------------------------
                    //throw new Exception();
                    transaction.Commit();
                }


                return(Json(new { isError = 0, msg = localizer["SavedSuccessfully"] }));
            }
            catch (ApplicationException ex)
            {
                return(Json(new
                {
                    isError = 1,
                    msg = ex.Message
                }));
            }
            catch (DbUpdateException ex)
            {
                Global.LogException(HttpContext, ex);

                return(Json(new
                {
                    isError = 1,
                    msg = localizer["UnableToSaveTryAgainOrCallUs"]
                }));
            }
            catch (Exception ex)
            {
                Global.LogException(HttpContext, ex);
                return(Json(new
                {
                    isError = 1,
                    msg = ex.Message
                }));
            }
        }