示例#1
0
        /// <returns>Virtual path to the file with extension</returns>
        public MethodResult <string> UploadImage(HttpPostedFileBase file, UploadLocationEnum location, bool enableSizeValidation = true)
        {
            MethodResult <string> result = MethodResult <string> .Success;

            if (file == null || file.ContentLength == 0)
            {
                throw new UserReadableException("File is empty or does not exist");
            }

            var tempPath = Path.GetTempFileName();

            file.SaveAs(tempPath);

            Image img = Image.FromFile(tempPath);

            if (enableSizeValidation)
            {
                result.Merge(checkIfImageIsCorrect(img));
            }

            if (result.IsError)
            {
                return(result);
            }

            var fileName = GetUniqueFilePath(location, ".png");

            Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            var imageFile = File.Create(fileName);


            img.Save(imageFile, ImageFormat.Png);
            img.Dispose();
            File.Delete(tempPath);
            imageFile.Close();


            result.ReturnValue = "\\" + fileName.Replace(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"], string.Empty);
            return(result);
        }
示例#2
0
        public MethodResult Work(int citizenID, int companyID)
        {
            var result = new MethodResult();

            using (var t = transactionScopeProvider.CreateTransactionScope())
            {
                var company  = companyRepository.GetById(companyID);
                var citizen  = citizenRepository.First(c => c.ID == citizenID);
                var employee = company.CompanyEmployees.First(e => e.CitizenID == citizen.ID);


                produceProduct(company, citizen);
                updateCitizenAfterWork(company, citizen);
                result.Merge(payCashForWork(company, citizen, employee));


                if ((citizen.DayWorkedRow % 30) == 0)
                {
                    citizenService.ReceiveHardWorker(citizen);
                }
                var transaction = System.Transactions.Transaction.Current;

                if (transaction.TransactionInformation.Status == System.Transactions.TransactionStatus.Aborted)
                {
                    throw new UserReadableException("You cannot work");
                }

                company.InformedAboutNotEnoughSalaryToday = false;
                company.InformedAboutNotEnoughRawToday    = false;

                companyRepository.SaveChanges();

                t.Complete();
            }

            return(result);
        }